package com.wjk.kylin.mall.order.feign.fallback;

import com.wjk.kylin.mall.common.core.dto.base.DataOutDTO;
import com.wjk.kylin.mall.order.feign.ProductFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Service;

/**
 * 调用方熔断保护 Factory
 * 可以打印异常等处理
 */
@Slf4j
@Service
public class ProductFeignServiceFallbackFactory implements FallbackFactory<ProductFeignService> {
    @Override
    public ProductFeignService create(Throwable throwable) {
        return new ProductFeignService() {
            @Override
            public DataOutDTO<String> demo() {
                log.error("ProductFeignService.test 熔断异常：{}",throwable.getMessage());
                DataOutDTO<String> dto = new DataOutDTO<>();
                dto.setData("ProductFeignServiceFallbackFactory.demo");
                return dto;
            }
        };
    }
}
